<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>策略模式</title>
</head>

<body>
  <script>
    //根据不同方式计算奖金
    //代码如下：
    var obj = {
      "A": function (salary) {
        return salary * 4;
      },
      "B": function (salary) {
        return salary * 3;
      },
      "C": function (salary) {
        return salary * 2;
      }
    };
    var calculateBouns = function (level, salary) {
      return obj[level](salary);
    };
    console.log(calculateBouns('A', 10000)); // 40000
  </script>
</body>

</html>